import Vue from 'vue'
import App from './App'
import store from './store'

import uView from "./uni_modules/uview-ui";
Vue.use(uView);

Vue.config.productionTip = false

App.mpType = 'app'

// Vue.prototype.$base_url = 'http://www.nrunning.com/phone/';
Vue.prototype.$base_url = 'https://dz.nrunning.com/phone/';



Vue.prototype.$img_src = 'https://shop-made.oss-cn-hangzhou.aliyuncs.com/';

Vue.prototype.$store = store
// Vue.prototype.uploads = (url,data) =>{
// 	uni.uploadFile({
// 	    url: url, //仅为示例，非真实的接口地址
// 	    filePath: tempFilePaths[0],
// 	    name: 'file',
// 	    formData: {
// 	        'user': 'test'
// 	    },
// 	    success: (uploadFileRes) => {
// 	        console.log(uploadFileRes.data);
// 	    }
// 	});
// }
String.prototype.GetLen = function () {
	var regEx = /^[\u4e00-\u9fa5\uf900-\ufa2d]+$/;
	if (regEx.test(this)) {
		return this.length * 2;
	} else {
		var oMatches = this.match(/[\x00-\xff]/g);
		var oLength = this.length * 2 - oMatches.length;
		return oLength;
	}
};
// const mount=  Vue.prototype.$mount
// Vue.prototype.$mount = function (
//   el?: string | Element,
//   hydrating?: boolean
// ): Component {
//   // 获取el对应的dom
//   el = el && inBrowser ? query(el) : undefined
//   // 第三步解析 mountComponent
//   return mountComponent(this, el, hydrating)
// };
//ajax
// Vue.prototype.loading = "https://shop-made.oss-cn-hangzhou.aliyuncs.com/loading.gif"
Vue.prototype.ajax = (url, data) => {
	var temp_data = data.data;
	if (temp_data == undefined) temp_data = {};
	var urls = '/phone/' + url;
	var header = {
		'Content-Type': 'application/json'
	};
	// uni.showLoading({
	// 	mask: true
	// });
	uni.request({
		url: urls,
		data: temp_data,
		method: "POST",
		header: header,
		success: (res) => {
			// uni.hideLoading();
			res = res.data;
			//未登录
			if (res.code == 4) {
				uni.showModal({
					title: '提示',
					content: '请先登录',
					showCancel: true,
					success: (res) => {
						if (res.confirm) {
							uni.reLaunch({
								url: './../login/login',
							})
						} else if (res.cancel) {
							uni.reLaunch({
								url: './../index/homePage'
							})
						}
					}
				});
			}
			data.success(res)
		},
		fail: () => {
			uni.showToast({
				title: '请求失败',
				duration: 2000,
				icon: 'none'
			});

		},
		complete: () => {}
	})
};
//弹窗
Vue.prototype.toast = (msg) => {
	uni.showToast({
		title: msg,
		duration: 2000,
		position: 'bottom',
		icon: 'none',
		mask: true
	});
};

const app = new Vue({
	...App
})
app.$mount()